/*********************************************************************************
 * Software License Agreement (BSD License)
 * Copyright (c) 2012, Carlos D. Correa (info@ngraph.org)
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of netzen nor the
 *    names of its contributors may be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *********************************************************************************/
#ifndef TABBAR_H
#define TABBAR_H

#include <QTabWidget>
#include <QListView>
#include <QToolBox>
#include <QTreeView>
#include <QTableView>
#include <QProgressBar>
#include <QStandardItemModel>
#include <QLabel>

#include <map>
using namespace std;
#include "controller.h"
#include "propertyInspectorDelegate.h"

class Tabbar: public QWidget
{
    Q_OBJECT
    

public:
    Tabbar(Controller *controller, QWidget *parent=0);

private slots:

private:
    Controller *controller;
};

class Info: public QWidget, DataListener
{
    Q_OBJECT
protected:
    Controller *controller;
    QLabel *sources;
    void updateInfo();
public:
    Info(Controller *controller, QWidget *parent = 0);
    void dataAdded(const char *source, string event);
};

class Inspector: public QWidget, ViewListener 
{
    Q_OBJECT
    QTreeView *tree;
    //QTableView *table;
		QTreeView *propertyTree;
    QStandardItemModel *model;
    QStandardItemModel *propertyModel;
    View *currentView;
    QStandardItem *root;
		QToolBox * toolBox;
		map<string, QStandardItemModel *> propertyModels;
		map<string, QTableView *> tables;
    map<string, QStandardItem *> types;
public:
    Inspector(Controller *controller, QWidget *parent = 0);
    void viewAdded(View *view);
		bool tableExists(string name);
		bool createTable(string name);
private:
    Controller *controller;
		QTableView *getTable(string name);
		QStandardItemModel *getPropertyModel(string name);
		QStandardItemModel *createPropertyModel(string typeName);
		void addPropertyModel(string name, QStandardItemModel *model);
		void createTable(string name, QStandardItemModel *model);
		void setupTable(string name);
protected:
	void addView(string type, string name);

    //  PropertyInspectorDelegate * createDelegate();

public slots:
    void clicked(const QModelIndex &index);
    void propertyChanged(QStandardItem *item);

};

class Mapping: public QWidget 
{
    Q_OBJECT
public:
    Mapping(Controller *controller, QWidget *parent = 0);
private:
    Controller *controller;

};

class Transforms : public QWidget, ProgressListener
{
    Q_OBJECT
    QTreeView *tree;
    QStandardItem *root;
    map<string, QStandardItem *> types;

    QTableView *table;
    QStandardItemModel *propertyModel;
    QStandardItemModel *model;
    QProgressBar *progressBar;
    AnalysisTool *currentTool;
public:
    Transforms(Controller *controller, QWidget *parent = 0);
private:
    Controller *controller;

public slots:
    void clicked(const QModelIndex &idx);
    void computePressed();
    void propertyChanged(QStandardItem *item);
    virtual void setProgress(float progress);
    virtual void done();

};

class Layouts : public QWidget, ProgressListener, LayoutListener
{
    Q_OBJECT
    QTreeView *tree;
    QStandardItem *root;
    map<string, QStandardItem *> types;

    QTableView *table;
    QStandardItemModel *propertyModel;
    QStandardItemModel *model;
    QProgressBar *progressBar;
    Layout *currentLayout;
public:
    Layouts(Controller *controller, QWidget *parent = 0);
private:
    Controller *controller;

public slots:
    void clicked(const QModelIndex &idx);
    void computePressed();
    void propertyChanged(QStandardItem *item);
    virtual void setProgress(float progress);
    virtual void done();
    virtual void layoutAdded(Layout *layout);
};


class Datatab: public QWidget, DataListener
{
    Q_OBJECT
public:
    Datatab(Controller *controller, QWidget *parent = 0);
    void dataAdded(const char *source, string event);

private:
    Controller *controller;

};

#endif
